package gamedsl.game;

import gamedsl.event.Event;
import gamedsl.event.EventTracker;
import net.phys2d.raw.CollisionEvent;
import org.newdawn.penguin.*;
import org.newdawn.slick.SlickException;

public class MushroomReward extends RectangularEntity{
	
	public MushroomReward(float x, float y, float width, float height, float mass, String name, String type, int value) throws SlickException{
		//super(x,y,width,height,mass,name,type, "res/mushroom.gif");
		super(x,y,width,height,mass,name,type, "res/mushroom.gif", value);
		
		
	}
	
	public void update(int delta) {
		//Check if collision
		checkCollision();
		
	}
	
	private void checkCollision(){
		CollisionEvent[] events = world.getContacts(body);
		for(int i = 0; i < events.length; i++){
			Object b = events[i].getBodyA().getUserData();
			AbstractEntity e = (AbstractEntity)b;
			if(e != null){
				//Cases
				//  Collision with Player
				if(e.getType() == "Player"){
					System.out.println("Player hit " + this.getType() + " " + this.getId());
						EventTracker.getInstance().triggerEvent("MushroomRewardHitEvent", new Event("MushroomRewardHitEvent", this, e));
				}
				//Other cases
				// E.g. Collision with other actors
			}
		}
		
	}
	@Override
	public void handleEvent(Event event) {
		String message = event.getMessage();
		
	}
}
